package com.sqsf.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LogAspect {

    // 定义切入点：匹配Service层所有方法
    @Pointcut("execution(* com.sqsf.service.*.*(..))")
    public void servicePointcut() {}

    // 后置通知：在方法执行后打印日志
    @After("servicePointcut()")
    public void logAfter(JoinPoint joinPoint) {
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        String methodName = signature.getMethod().getName();
        System.out.println("执行了[" + methodName + "]操作");
    }
}